//
//  LGAccount.m
//  微博
//
//  Created by MS on 15-12-6.
//  Copyright (c) 2015年 MS. All rights reserved.
//
/*
 {
 "access_token" = "2.00CnYaJCzQBWZB1e189662bbOczERD";
 "expires_in" = 157679999;
 "remind_in" = 157679999; //废弃
 uid = 1973966232;
 }
 */


#import "LGAccount.h"
#import "MJExtension.h"
#define LGAccess_tokenKey @"access_token"
#define LGExpires_inKey @"expires_in"
#define LGUidKey @"uid"
#define LGDateKey @"date"
#define LGNameKey @"name"
@implementation LGAccount

MJCodingImplementation //归解档方法

+(instancetype) accountWithDic:(NSDictionary *)dic
{
    
    LGAccount * account = [[self alloc] init];
    
    [account setValuesForKeysWithDictionary:dic];
    
    return account;
    
}

-(void)setExpires_in:(NSString *)expires_in
{
    _expires_in = expires_in;
    
    //计算过期时间 = 当前时间+有效期
    _expires_date = [NSDate dateWithTimeIntervalSinceNow:[_expires_in longLongValue]];
    
}


//归档时候调用，告诉系统哪个属性需要归档，如何归档
//-(void)encodeWithCoder:(NSCoder *)aCoder
//{
//    [aCoder encodeObject:_access_token forKey:LGAccess_tokenKey];
//    [aCoder encodeObject:_expires_in forKey:LGExpires_inKey];
//    [aCoder encodeObject:_uid forKey:LGUidKey];
//    [aCoder encodeObject:_expires_date forKey:LGDateKey];
//    [aCoder encodeObject:_name forKey:LGNameKey];
//}
//
//-(id)initWithCoder:(NSCoder *)aDecoder
//{
//    if (self = [super init]) {
//        
//        /**
//         *  一定要赋值！！！
//         */
//        
//        _access_token = [aDecoder decodeObjectForKey:LGAccess_tokenKey];
//        _expires_in = [aDecoder decodeObjectForKey:LGExpires_inKey];
//        _uid = [aDecoder decodeObjectForKey:LGUidKey];
//        _expires_date = [aDecoder decodeObjectForKey:LGDateKey];
//        _name = [aDecoder decodeObjectForKey:LGNameKey];
//        
//    }
//    
//    return self;
//}

@end
